package com.example.admin.yuejian_22.Activity;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import com.example.admin.yuejian_22.Adapter.ClubSearchAdapter;
import com.example.admin.yuejian_22.Bean.ClubList;
import com.example.admin.yuejian_22.Listener.UserListener;
import com.example.admin.yuejian_22.Model.UserModel;
import com.example.admin.yuejian_22.R;

import java.util.List;


public class SearchClubActivity extends Activity {
    private ImageButton back_club;
    private View view = null;
    private ClubSearchAdapter adapter = null;
    List<ClubList> clubListsearch = null;
    private Button button_search;
    private EditText keywordView;
    private RecyclerView recycleviewclub;
    private Context getcontext(){
        return this;
    }
    UserListener userListener = new UserListener() {
        @Override
        public void onResponse(Object beanobject) {
            recycleviewclub.setAdapter(new ClubSearchAdapter(getcontext(),(List<ClubList>)beanobject));
            adapter.getSearchClub(clubListsearch);
            adapter.notifyDataSetChanged();
        }
        @Override
        public void onFail(String msg) {
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search_club);
        initRecyclerView(view);

        back_club = (ImageButton) findViewById(R.id.back_club);
        keywordView = (EditText) findViewById(R.id.textView_keyword);
        button_search = (Button) findViewById(R.id.button_search);

        button_search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                UserModel model = new UserModel();
                final String club_name = keywordView.getText().toString();
                model.getSearchClub(club_name,userListener);
            }

    });

        back_club.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    public  void initRecyclerView(View view){
        recycleviewclub=(RecyclerView) findViewById(R.id.recycleview_search);
        recycleviewclub.setLayoutManager(new LinearLayoutManager(this));
        recycleviewclub.setItemAnimator(new DefaultItemAnimator());
        adapter = new ClubSearchAdapter(this,clubListsearch);
    }
}
